package com.liu.community.dto;/*
 *@Author:Liu Xing-zhi
 *Description:
 *Date:Crated in 9:21 2021/10/13
 */

import com.liu.community.exception.CustomerException;
import com.liu.community.exception.ErrorCode;
import lombok.Data;

@Data
public class ResponseDto<T> {
    private  Integer code;
    private  String message;
    private  T data;

    public  static  ResponseDto errorOF(Integer code,String message){
        ResponseDto responseDto = new ResponseDto();
        responseDto.setCode(code);
        responseDto.setMessage(message);
        return responseDto;
    }
    public  static  ResponseDto errorOF(ErrorCode errorCode){
        return errorOF(errorCode.getCode(),errorCode.getMessage());
    }

    public  static  ResponseDto loginOK(){
        ResponseDto responseDto = new ResponseDto();
        responseDto.setCode(200);
        responseDto.setMessage("操作成功！");
        return responseDto;
    }
    public  static  ResponseDto errorOF(CustomerException errorCode){
        return errorOF(errorCode.getCode(),errorCode.getMessage());
    }

    public  static  <T> ResponseDto okOf(T t){
        ResponseDto responseDto = new ResponseDto();
        responseDto.setCode(200);
        responseDto.setMessage("操作成功！");
        responseDto.setData(t);
        return responseDto;
    }
}
